﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Knlght.Domain
{
    /// <summary>
    /// 单个对象回复类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ItemResponse<T> : ResponseBase
    {
        public ItemResponse(bool isSuccess = true, string error = "", int resultCode = -1) : base(isSuccess, error, resultCode)
        {
        }

        /// <summary>
        /// 获取到的回复对象
        /// </summary>
        public T Model { get; set; }

        #region 辅助方法
        /// <summary>
        /// 创建 成功获取单个对象的回复对象
        /// </summary>
        public static ItemResponse<T> CreateResponseBySuccess(T model)
        {
            return new ItemResponse<T>(true) { Model = model };
        }
        /// <summary>
        /// 获取操作失败的回复对象
        /// </summary>
        public static ItemResponse<T> CreateResponseByFail(string error, int resultCode = ResultCodeConstants.NONE)
        {
            return new ItemResponse<T>(false, error, resultCode);
        }
        #endregion
    };
}
